import { checkCancelOrder } from '@/api/order'
import { ref } from 'vue'

// 驳回加载
const rejectLoading = ref(false)

/**
 * 驳回方法
 * @param {string} orderId - 工单id
 * @param {string} cancelOrderId - 取消工单id
 * @param {string} remark - 审核备注
 */
const reject = async (orderId: string, cancelOrderId: string, remark: string) => {
  rejectLoading.value = true
  const res = await checkCancelOrder(orderId, { checkType: 2, id: cancelOrderId, remark })
  rejectLoading.value = false
  return res.data as { data: object; message: string; code: number; success: boolean }
}

// 通过加载
const allowLoading = ref(false)

/**
 * 通过方法
 * @param {string} orderId - 工单id
 * @param {string} cancelOrderId - 取消工单id
 * @param {string} remark - 审核备注
 */
const allow = async (orderId: string, cancelOrderId: string, remark: string) => {
  rejectLoading.value = true
  const res = await checkCancelOrder(orderId, { checkType: 1, id: cancelOrderId, remark })
  rejectLoading.value = false
  return res.data as { data: object; message: string; code: number; success: boolean }
}

export default {
  allowLoading,
  rejectLoading,
  allow,
  reject,
}
